package com.wendjia.demo.controller;

import com.alibaba.fastjson.JSON;
import com.wendjia.demo.config.DemoProperties;
import com.wendjia.demo.dao.UserDao;
import com.wendjia.demo.model.User;
import com.wendjia.demo.service.IUserService;
import com.wendjia.demo.service.impl.UserServiceImp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * Created by wendjia on 2017/3/8.
 */
@RestController
@EnableAutoConfiguration
@RequestMapping("/user")  //所有方法都会在这个url下
@EnableMongoRepositories(basePackages = "com.wendjia.demo.dao")
public class UserController {
    @Autowired
    private UserServiceImp userService;

    @RequestMapping(value={"/insert","/add"},method = RequestMethod.GET)  //多个
    public User index(@RequestParam(value = "name" , required = false,defaultValue = "") String name,
                        @RequestParam(value = "password" , required = false,defaultValue = "") String password) {
        User user =  userService.saveUser(new User(name,password));
        return user;
    }
    @RequestMapping(value="/get")  //多个
    public List<User> getUsers() {
        List<User>  list= userService.findAll();
        return list;
    }

}
